String clazzTpl({package}) => """
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:$package/utils/encrypt_util.dart';
import 'package:$package/debug/slice/actions.dart';
import 'package:$package/debug/app_debug_model.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:package_info_plus/package_info_plus.dart';
import 'package:$package/widget/base_store_container.dart';

enum Mode {
  // 开发
  dev,
  // 预览
  preview,
  // 生产
  prod,
}

class AppConfigState {
  List<AppDebugModel>? appDebug;

  AppConfigState({this.appDebug});

  bool findAppDebug(AppDebugKey key) {
    bool on = false;
    appDebug?.forEach((element) {
      if (element.key == key) {
        on = element.on;
      }
    });
    return on;
  }

  String findAppHost() {
    try {
      final item =
          appDebug?.firstWhere((element) => element.key == AppDebugKey.hosts);
      return item!.childList!.firstWhere((element) => element.isDef).value;
    } catch (_) {}
    return '';
  }

  String findH5FaceHost() {
    try {
      final item = appDebug
          ?.firstWhere((element) => element.key == AppDebugKey.h5FaceHosts);
      return item!.childList!.firstWhere((element) => element.isDef).value;
    } catch (_) {}
    return '';
  }

  String findAppHostEnv() {
    try {
      final item =
          appDebug?.firstWhere((element) => element.key == AppDebugKey.hosts);
      final envItem = item!.childList!.firstWhere((element) => element.isDef);
      return envItem.key.split(".").last;
    } catch (_) {}
    return '';
  }

  bool isTestAppHostEnv() {
    try {
      final item =
          appDebug?.firstWhere((element) => element.key == AppDebugKey.hosts);
      final envItem = item!.childList!.firstWhere((element) => element.isDef);
      return envItem.key.split(".").last == 'test';
    } catch (_) {}
    return false;
  }

  bool isProdAppHostEnv() {
    try {
      final item =
          appDebug?.firstWhere((element) => element.key == AppDebugKey.hosts);
      final envItem = item!.childList!.firstWhere((element) => element.isDef);
      return envItem.key.split(".").last == 'prod';
    } catch (_) {}
    return false;
  }

  String findProgramMode() {
    try {
      final item = appDebug
          ?.firstWhere((element) => element.key == AppDebugKey.programMode);
      return item!.childList!.firstWhere((element) => element.isDef).value;
    } catch (_) {}
    return '';
  }

  String findJSCoreMode() {
    try {
      final item = appDebug
          ?.firstWhere((element) => element.key == AppDebugKey.jsCoreMode);
      return item!.childList!.firstWhere((element) => element.isDef).value;
    } catch (_) {}
    return '';
  }

  AppDebugModel? findAppDebugItem(AppDebugKey key) {
    return appDebug?.firstWhere((element) => element.key == key);
  }

  static void themeNotify(BuildContext context) {
    if (StaticStore.store != null) {
      var item = StaticStore.store!.state.appConfigState!
          .findAppDebugItem(AppDebugKey.themes);
      if (item!.childList != null) {
        for (var e1 in item.childList!) {
          if (e1.isDef) {
            StaticStore.store!.dispatch(
                ThemeActions.updateTheme(ThemeState.formatThemeType(e1.value)));
          }
        }
      }
    }
  }

  void updateAppDebug(AppDebugModel model) {
    var state = StaticStore.store!.state.appConfigState!;
    appDebug = appDebug?.map((e) {
      if (e.key == model.key) {
        return model;
      }
      return e;
    }).toList();
    StaticStore.store!.dispatch(AppConfigActions.updateAppConfig(state));
  }

  AppConfigState copyWith({
    appDebug,
  }) {
    return AppConfigState(appDebug: appDebug ?? this.appDebug);
  }

  static AppConfigState fromJson(dynamic json) {
    return AppConfigState(
      appDebug: (json["appDebug"] as List)
          .map((e) => AppDebugModel.fromJson(e))
          .toList(),
    );
  }

  dynamic toJson() => {
        'appDebug': appDebug?.map((v) => v.toJson()).toList(),
      };

  static AppConfigState initialState() {
    return AppConfigState(
      appDebug: [
        AppDebugModel(key: AppDebugKey.debugBanner, title: 'DebugBanner'),
        AppDebugModel(key: AppDebugKey.dev, title: '开发模式', on: false),
        AppDebugModel(key: AppDebugKey.policy, title: '隐私政策'),
        AppDebugModel(
          key: AppDebugKey.websocket,
          title: 'websocket设置',
          desc: 'wss://xxxx.com/websocket',
        ),
        AppDebugModel(
          key: AppDebugKey.proxy,
          title: '代理设置',
        ),
        AppDebugModel(
          key: AppDebugKey.themes,
          title: '主题',
          childList: [
            DataModel(
              isDef: true,
              key: '浅色',
              value: 'light',
            ),
            DataModel(
              key: '深色',
              value: 'dark',
            ),
            DataModel(
              key: '跟随系统',
              value: 'system',
            ),
          ],
        ),
        AppDebugModel(
          key: AppDebugKey.hosts,
          title: 'host设置',
          childList: [
            DataModel(
              key: 'dev',
              value: 'https://xxxx.com/',
            ),
            DataModel(
              key: 'test',
              value: 'https://xxxx.com/',
            ),
            DataModel(
              isDef: true,
              key: 'uat',
              value: 'https://xxxx.com/',
            ),
            DataModel(
              key: 'prod',
              value: 'https://xxxx.com/',
            ),
          ],
        ),
        AppDebugModel(
          key: AppDebugKey.h5FaceHosts,
          title: 'H5人脸认证host设置',
          childList: [
            DataModel(
              key: 'dev',
              value: 'https://xxxx.com/',
            ),
            DataModel(
              key: 'test',
              value: 'https://xxxx.com/',
            ),
            DataModel(
              isDef: true,
              key: 'uat',
              value: 'https://xxxx.com/',
            ),
            DataModel(
              key: 'prod',
              value: 'https://xxxx.com/',
            ),
          ],
        ),
        AppDebugModel(
          key: AppDebugKey.programMode,
          title: '小程序模式',
          childList: [
            DataModel(
              key: Mode.dev.name,
              value: Mode.dev.name,
            ),
            DataModel(
              key: Mode.preview.name,
              value: Mode.preview.name,
            ),
            DataModel(
              isDef: true,
              key: Mode.prod.name,
              value: Mode.prod.name,
            ),
          ],
        ),
        AppDebugModel(
          key: AppDebugKey.jsCoreMode,
          title: 'JSCore模式',
          childList: [
            DataModel(
              key: Mode.dev.name,
              value: Mode.dev.name,
            ),
            DataModel(
              key: Mode.preview.name,
              value: Mode.preview.name,
            ),
            DataModel(
              isDef: true,
              key: Mode.prod.name,
              value: Mode.prod.name,
            ),
          ],
        ),
        AppDebugModel(key: AppDebugKey.cleanMock, title: '清除mock数据'),
        AppDebugModel(key: AppDebugKey.documentDir, title: '文档目录'),
      ],
    );
  }
}

class AppAndDevice {
  static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin();

  ///指纹信息 设备唯一信息
  static String mur = '';
  static String deviceId = '';
  static String deviceType = '';
  static String deviceVersion = '';
  static String appPackage = '';
  static String appVersion = '';
  static String appBuildNumber = '';

  // Uri.encodeFull
  static String deviceDisplay = '';
  static String deviceManufacturer = '';
  static bool isPhysicalDevice = true;
  // 网络信息mobile wifi
  static String deviceNet = '';

  static Future<void> loadDevice() async {
    try {
      if (Platform.isAndroid) {
        AndroidDeviceInfo deviceData = await deviceInfoPlugin.androidInfo;
        deviceId = deviceData.id;
        deviceDisplay = Uri.encodeFull(deviceData.model);
        deviceManufacturer = deviceData.manufacturer;
        deviceType = 'android';
        deviceVersion = deviceData.version.release;
        isPhysicalDevice = deviceData.isPhysicalDevice;
      } else if (Platform.isIOS) {
        IosDeviceInfo deviceData = await deviceInfoPlugin.iosInfo;
        deviceId = deviceData.identifierForVendor ?? "";
        deviceDisplay = Uri.encodeFull(deviceData.name ?? "");
        deviceManufacturer = deviceData.model ?? "";
        deviceType = 'iOS';
        deviceVersion = deviceData.systemVersion ?? "";
        isPhysicalDevice = deviceData.isPhysicalDevice;
      }
      await loadAppPackageInfo();
      deviceNet = (await (Connectivity().checkConnectivity())).name;
      mur = EncryptUtil.encodeMD5("\${deviceId}_\${deviceType}_\$deviceVersion");
    } catch (_) {}
  }

  static Future<void> loadAppPackageInfo() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    appPackage = packageInfo.packageName;
    appVersion = packageInfo.version;
    appBuildNumber = packageInfo.buildNumber;
  }
}
""";
